package com.hy.mechanicalarm.utils;

import com.hy.mechanicalarm.ui.bean.AngleCalResult;

public class AngleCalUtil {
	/**
	 * 根据入参angleY的值，计算入参angleZ的值是否在合理范围内
	 * 如通过，则返回对象中的code为CODE_SUCCESS
	 * 如不通过，则返回对象中的code为CODE_FAIL，且rangeMin和rangeMax内存入合理的数值
	 * 规则如下:
	 * 		y<30 		z:0-70
	 * 		30<=y<40 	z:0-n(70+y-30)
	 * 		40<=y<=65 	z:0-80
	 * 		y>65 		z:n(y-65)-80
	 * @param angleY
	 * @param angleZ
	 */
	public static AngleCalResult angleCal(int angleY , int angleZ) {
		AngleCalResult result = new AngleCalResult();
		int code = 0,rangeMin = 0,rangeMax = 0;
		if(angleY < 30) {
			if(0 < angleZ && angleZ <= 70) {
				code = AngleCalResult.CODE_SUCCESS;
			}else {
				code = AngleCalResult.CODE_FAIL;
				rangeMin = 0;
				rangeMax = 70;
			}
		}else if(30 <= angleY && angleY < 40) {
			int zMax = 70 + angleY - 30;
			if(0 < angleZ && angleZ <= zMax) {
				code = AngleCalResult.CODE_SUCCESS;
			}else {
				code = AngleCalResult.CODE_FAIL;
				rangeMin = 0;
				rangeMax = zMax;
			}
		}else if(40 <= angleY && angleY <= 65) {
			if(0 < angleZ && angleZ <= 80) {
				code = AngleCalResult.CODE_SUCCESS;
			}else {
				code = AngleCalResult.CODE_FAIL;
				rangeMin = 0;
				rangeMax = 80;
			}
		}else if(65 < angleY) {
			int zMin = angleY - 65;
			if(zMin < angleZ && angleZ <= 80) {
				code = AngleCalResult.CODE_SUCCESS;
			}else {
				code = AngleCalResult.CODE_FAIL;
				rangeMin = zMin;
				rangeMax = 80;
			}
		}
		
		result.setCode(code);
		result.setRangeMax(rangeMax);
		result.setRangeMin(rangeMin);
		return result;
	}
	

}
